/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aso.upna.rmi;

import aso.upna.playlist.GenericList;
import aso.upna.playlist.PlayList;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author javier
 */

public class UserHand extends UnicastRemoteObject implements UserHandler {

    private String almacen_perfiles_ip;
    private int almacen_perfiles_port;

    public UserHand(String ip,int port) throws RemoteException
    {
        super();
        this.almacen_perfiles_ip = new String(ip);
        this.almacen_perfiles_port = port;
    }

    public void nuevaPlaylist(PlayList p) throws RemoteException
    {
        UserHandler user_obj = null;
        try
        {
            user_obj = (UserHandler)Naming.lookup("rmi://" + almacen_perfiles_ip + ":" + almacen_perfiles_port + "/perfiles");
            user_obj.nuevaPlaylist(p);
        }

        catch (NotBoundException ex)
        {
            Logger.getLogger(UserHand.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (MalformedURLException ex)
        {
            Logger.getLogger(UserHand.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public GenericList listarPlaylist() throws RemoteException
    {

        UserHandler user_obj = null;
        GenericList l = null;
        try
        {
            user_obj = (UserHandler)Naming.lookup("rmi://" + almacen_perfiles_ip + ":" + almacen_perfiles_port + "/perfiles");
            l = user_obj.listarPlaylist();
            return l;
        }
        catch (NotBoundException ex)
        {
            return null;
        }
        catch (MalformedURLException ex)
        {
            return null;
        }
    }

    public boolean borrarPlaylist(String p_name) throws RemoteException
    {
        UserHandler user_obj = null;
        try
        {
            user_obj = (UserHandler)Naming.lookup("rmi://" + almacen_perfiles_ip + ":" + almacen_perfiles_port + "/perfiles");
            return user_obj.borrarPlaylist(p_name);
        }
        catch (NotBoundException ex)
        {
            return false;
        }
        catch (MalformedURLException ex)
        {
            return false;
        }
    }

    public boolean checkLogin(String user, String pass) throws RemoteException
    {
        UserHandler user_obj = null;
        try
        {
            user_obj = (UserHandler)Naming.lookup("rmi://" + almacen_perfiles_ip + ":" + almacen_perfiles_port + "/perfiles");
            return user_obj.checkLogin(user, pass);
        }
        catch (NotBoundException ex)
        {
            return false;
        }
        catch (MalformedURLException ex)
        {
            return false;
        }
    }

}
